package inner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 30318
 * Date: 2023-05-18
 * Time: 13:58
 */
class OuterClass2{
    public int data1 = 1;
    int data2 = 2;
    public static int data3 = 3;

    public void test(){
        System.out.println("out::test()");
    }

    /**
     * 1.如何获取静态内部类对象？
     * OuterClass2.InnerClass2 innerClass2 = new OuterClass2.InnerClass2();
     * 2.静态内部类当中 不能访问外部类的非静态成员。外部类的非静态成员 需要通过外部类的对象的引用才能访问
     * 如果非要访问：OuterClass2 outerClass = new OuterClass2();
     *             System.out.println(outerClass.data1);
     */
    static class InnerClass2{
        public int data4 = 4;
        int data5 = 5;
        public static int data6 = 6;

        public void func(){
            System.out.println("out::func()");

            OuterClass2 outerClass = new OuterClass2();
            System.out.println(outerClass.data1);

            /*System.out.println(data1);
            System.out.println(data2);*/

            System.out.println(data3);
            System.out.println(data4);
            System.out.println(data5);
            System.out.println(data6);
        }
    }
}
class Person{
    public int age = 18;
    public String name = "lihua";

    public void show(){
        System.out.println("姓名："+name+" 年龄："+age);
    }

    @Override
    public String toString() {
        return "Person{" +
                "age=" + age +
                ", name='" + name + '\'' +
                '}';
        //return "姓名："+name+" 年龄："+age;
    }
}

public class Test2 {

    public static void main(String[] args) {
        Person person = new Person();
        //person .show();
        System.out.println(person);
    }

    public static void main2(String[] args) {
        Person person = new Person();
        System.out.println(person.age);
        System.out.println(person.name);
        new Person();
        System.out.println(new Person().age);//匿名对象
        System.out.println(new Person().name);//匿名对象 只能使用一次

        new Person(){

        };
    }

    public void func(){
        //局部内部类
        class Inner{
            public void test(){
                System.out.println("=========");
            }
        }
        Inner inner = new Inner();
        inner.test();
    }

    public static void main1(String[] args) {

        OuterClass2.InnerClass2 innerClass2 = new OuterClass2.InnerClass2();

    }
}
